import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:provider/provider.dart';
import 'package:tiktokadult/assets_tool/images.dart';
import 'package:tiktokadult/hj_page/cartoon_business/cartoon_sub_module_page.dart';
import 'package:tiktokadult/hj_page/community_business/community_main_page_page/community_section_tab.dart';
import 'package:tiktokadult/hj_page/home_business/search_page/search_main_page.dart';
import 'package:tiktokadult/hj_page/main_page/provider/module_provider.dart';
import 'package:tiktokadult/hj_utils/holiday_theme.dart';
import 'package:tiktokadult/hj_utils/screen.dart';
import 'package:tiktokadult/hj_utils/widget_utils.dart';
import 'package:tiktokadult/tools_base/widget/keep_alive_widget.dart';

import '../../../assets_tool/app_colors.dart';
import 'community_main_logic.dart';

//资源
class CommunityMainPage extends StatefulWidget {
  final int index;
  final int subTabIndex;

  CommunityMainPage({super.key, this.index = 0, this.subTabIndex = 0});

  @override
  State<StatefulWidget> createState() {
    return CommunityMainPageState();
  }
}

class CommunityMainPageState extends State<CommunityMainPage> with SingleTickerProviderStateMixin {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Consumer<CommunityModuleProvider>(builder: (_, provider, __) {
      return Stack(
        fit: StackFit.expand,
        children: [
          if (holidayTheme.openHoliday) ...[
            Container(color: AppColors.primaryColor),
            Positioned(
              top: 0,
              left: 0,
              right: 0,
              child: Image.asset(HolidayTheme.theme.findBg, fit: BoxFit.fitWidth),
            ),
          ],
          Scaffold(
            body: GetBuilder(
              init: CommunityMainLogic(index: widget.index),
              builder: (_) => Column(
                children: [
                  screen.paddingTop.sizeBoxH,
                  Row(
                    children: [
                      Expanded(
                        child: _buildTabbar(_),
                      ),
                      InkWell(
                        onTap: () => Get.to(SearchMainPage()),
                        child: Image.asset(
                          'search_icon.png'.commonImgPath,
                          width: 20,
                        ),
                      ),
                      16.sizeBoxW,
                    ],
                  ),
                  Expanded(
                    child: TabBarView(
                      controller: _.tabCtr,
                      children: [
                        //黄游
                        CartoonSubModulePage(
                          type: CommunityType.Game,
                          tabIndex: widget.index == 2 ? widget.subTabIndex : 0,
                        ).keepAlive,
                        //文字小说
                        CartoonSubModulePage(
                          type: CommunityType.TextNovel,
                          tabIndex: widget.index == 3 ? widget.subTabIndex : 0,
                        ).keepAlive,
                        //有声小说
                        CartoonSubModulePage(
                          type: CommunityType.VoiceNovel,
                          tabIndex: widget.index == 3 ? widget.subTabIndex : 0,
                        ).keepAlive,
                        //图集
                        CartoonSubModulePage(
                          type: CommunityType.Pic,
                          tabIndex: widget.index == 1 ? widget.subTabIndex : 0,
                        ).keepAlive,
                      ],
                    ),
                  )
                ],
              ),
            ),
          ),
        ],
      );
    });
  }

  _buildTabbar(CommunityMainLogic _) {
    return CommunitySectionTabMenu(
      _.tabs,
      curIndex: widget.index,
      tabController: _.tabCtr,
    );
  }

  @override
  void dispose() {
    // Get.delete<CommunityMainPageLogic>();
    super.dispose();
  }
}
